let prices = [7,1,5,3,6,4]

let maxProfit = function(prices){
    let max = 0
    for(let i = 0; i < prices.length; i++){
        for(let j = i; j < prices.length; j++){
            if(prices[j] > prices[i]){
                let temp = prices[j] - prices[i]
                max = Math.max(max, temp)
            }
        }
    }
    return max
}

console.log(maxProfit(prices))